/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.mrp.ppm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import merlion.common.util.Consts;

/**
 *
 * @author Zhang Ying
 */
@Entity
public class UpdateIndiv implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private Timestamp adaptedTime;
    private String adaptedType; // indicate to be whether "Moving Average" or "Exponential" in (Consts)
    private Integer movingAvgIndexN;  // only can be 3, 6, 9, 12
    private Long movingAvgResult;
    private Integer exponentialIndexN;
    private Double exponentialIndexA;
    private Long exponentialResult;
    
    private int updateIndex;
    
    @OrderBy("index")
    //@OneToMany(targetEntity=IndexNValue.class, cascade={CascadeType.ALL}, fetch= FetchType.EAGER)
    private List<IndexNValue> promotionList = new ArrayList<IndexNValue>(); // the size is the same as numOfMonth 6
    
    @OrderBy("index")
    //@OneToMany(targetEntity=IndexNValue.class, cascade={CascadeType.ALL}, fetch= FetchType.EAGER)
    private List<IndexNValue> humanAdjustList = new ArrayList<IndexNValue>(); // the size is the same as numOfMonth 6
    
    @OrderBy("index")
    //@OneToMany(targetEntity=IndexNValue.class, cascade={CascadeType.ALL}, fetch= FetchType.EAGER)
    private List<IndexNValue> finalValues = new ArrayList<IndexNValue>(); // the size is the same as numOfMonth 6

    public UpdateIndiv() {
    }

    public UpdateIndiv(Timestamp updatedTime, int updateIndex) {
        this.updateIndex = updateIndex;
        movingAvgIndexN = 0;
        movingAvgResult = new Long(0);
        adaptedType = Consts.FORECAST_METHOD_MOVAVG;
        adaptedTime = updatedTime;
        for (int i = 0; i < 6; i++) {
            IndexNValue temp1 = new IndexNValue(i, new Long(0));
            IndexNValue temp2 = new IndexNValue(i, new Long(0));
            IndexNValue temp3 = new IndexNValue(i, new Long(0));
            promotionList.add(temp1);
            humanAdjustList.add(temp2);
            finalValues.add(temp3);
        }
    }

    public String getFormattedDay() {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        return sdf.format(adaptedTime);
    }

    public int getUpdateIndex() {
        return updateIndex;
    }

    public void setUpdateIndex(int updateIndex) {
        this.updateIndex = updateIndex;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Timestamp getAdaptedTime() {
        return adaptedTime;
    }

    public void setAdaptedTime(Timestamp adaptedTime) {
        this.adaptedTime = adaptedTime;
    }

    public String getAdaptedType() {
        return adaptedType;
    }

    public void setAdaptedType(String adaptedType) {
        this.adaptedType = adaptedType;
    }

    public Double getExponentialIndexA() {
        return exponentialIndexA;
    }

    public void setExponentialIndexA(Double exponentialIndexA) {
        this.exponentialIndexA = exponentialIndexA;
    }

    public Integer getExponentialIndexN() {
        return exponentialIndexN;
    }

    public void setExponentialIndexN(Integer exponentialIndexN) {
        this.exponentialIndexN = exponentialIndexN;
    }

    public List<IndexNValue> getFinalValues() {
        return finalValues;
    }

    public void setFinalValues(List<IndexNValue> finalValues) {
        this.finalValues = finalValues;
    }

    public List<IndexNValue> getHumanAdjustList() {
        return humanAdjustList;
    }

    public void setHumanAdjustList(List<IndexNValue> humanAdjustList) {
        this.humanAdjustList = humanAdjustList;
    }

    public List<IndexNValue> getPromotionList() {
        return promotionList;
    }

    public void setPromotionList(List<IndexNValue> promotionList) {
        this.promotionList = promotionList;
    }

    public Integer getMovingAvgIndexN() {
        return movingAvgIndexN;
    }

    public void setMovingAvgIndexN(Integer movingAvgIndexN) {
        this.movingAvgIndexN = movingAvgIndexN;
    }

    public Long getExponentialResult() {
        return exponentialResult;
    }

    public void setExponentialResult(Long exponentialResult) {
        this.exponentialResult = exponentialResult;
    }

    public Long getMovingAvgResult() {
        return movingAvgResult;
    }

    public void setMovingAvgResult(Long movingAvgResult) {
        this.movingAvgResult = movingAvgResult;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof UpdateIndiv)) {
            return false;
        }
        UpdateIndiv other = (UpdateIndiv) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.mrp.ppm.entity.UpdateIndiv[ id=" + id + " ]";
    }
}
